using Microsoft.WindowsAzure;

namespace AzureContrib.WindowsAzure.StorageClient
{
	/// <summary>
	/// Extension methods for <see cref="CloudStorageAccount"/>
	/// </summary>
	public static class CloudStorageAccountExtensions
	{
		/// <summary>
		/// Am I referencing the development storage account?
		/// </summary>
		/// <param name="account">The <see cref="CloudStorageAccount"/> we are checking.</param>
		/// <returns>True if the <paramref name="account"/> is the development storage account.</returns>
		public static bool IsDevelopmentStorageAccount(this CloudStorageAccount account)
		{
			Assumes.NotNull(account, "account");
			var comparer = new CloudStorageAccountComparer();
			return comparer.Equals(account, CloudStorageAccount.DevelopmentStorageAccount) ||
						 comparer.Equals(account, FiddlerDevelopementStorageHelper.DevelopmentStorageAccount);			
		}

		/// <summary>
		/// Get back the <see cref="CloudStorageAccount"/> from the <paramref name="cloudStorageAccount"/>
		/// </summary>
		/// <param name="cloudStorageAccount">Our starting point</param>
		/// <returns>The wrapped <see cref="CloudStorageAccount"/></returns>
		public static CloudStorageAccount Unwrap(this ICloudStorageAccount cloudStorageAccount)
		{
			return CloudStorageAccountWrapper.FromICloudStorageAccount(cloudStorageAccount);
		}

		/// <summary>
		/// Get the contract wrapping up <see cref="CloudStorageAccount"/>
		/// </summary>
		/// <param name="cloudStorageAccount">Our starting point</param>
		/// <returns>The <see cref="ICloudStorageAccount"/></returns>
		public static ICloudStorageAccount Wrap(this CloudStorageAccount cloudStorageAccount)
		{
			return new CloudStorageAccountWrapper(cloudStorageAccount);
		}

		/// <summary>
		/// Create a <see cref="ICloudQueueClient"/> from a <see cref="ICloudStorageAccount"/>
		/// </summary>
		/// <param name="cloudStorageAccount">The <see cref="ICloudStorageAccount"/></param>
		/// <returns><see cref="ICloudQueueClient"/></returns>
		public static ICloudQueueClient CreateCloudQueueClient(this ICloudStorageAccount cloudStorageAccount)
		{
			return new CloudQueueClientWrapper(cloudStorageAccount.QueueEndpoint, cloudStorageAccount.Credentials);
		}

		/// <summary>
		/// Create a <see cref="ICloudQueueClient"/> from a <see cref="ICloudStorageAccount"/>
		/// </summary>
		/// <param name="cloudStorageAccount">The <see cref="ICloudStorageAccount"/></param>
		/// <returns><see cref="ICloudQueueClient"/></returns>
		public static ICloudBlobClient CreateCloudBlobClient(this ICloudStorageAccount cloudStorageAccount)
		{
			return new CloudBlobClientWrapper(cloudStorageAccount.BlobEndpoint, cloudStorageAccount.Credentials);
		}

		/// <summary>
		/// Create a <see cref="ICloudQueueClient"/> from a <see cref="ICloudStorageAccount"/>
		/// </summary>
		/// <param name="cloudStorageAccount">The <see cref="ICloudStorageAccount"/></param>
		/// <returns><see cref="ICloudQueueClient"/></returns>
		public static ICloudTableClient CreateCloudTableClient(this ICloudStorageAccount cloudStorageAccount)
		{
			return new CloudTableClientWrapper(cloudStorageAccount.TableEndpoint, cloudStorageAccount.Credentials);
		}
	}
}